
# FIGURES APPEARING IN PAPER: 
# VOLATILE TOP INCOME SHARES IN SWITZERLAND? REASSESSING THE EVOLUTION BETWEEN 1981 AND 2010
# Note: change the paths in lines 13 and 14 below in accordance with your OS

library(foreign)
library(ggplot2)
library(RColorBrewer)
library(grid)
library(scales)

rm(list=ls()) # remove all stored objects
source("/Users/isabel/PhD/Dropbox/Top Income Shares/R&R/CODE2/fine_grid.R")
setwd("/Users/isabel/PhD/Dropbox/Top Income Shares/R&R/CODE2/results/figures")


# Figure 1. Time Series plot cantons
mydata<-read.dta("fig1.dta")
tail(mydata)

data <- subset(mydata, year <= 2008) 

p <- ggplot(data )
p +  geom_line(aes( y= P99d_ipol_missing, x=year,shape=kanton,linetype=kanton,color=kanton), size=3.5) + 
  geom_point(aes( y=P99d, x=year,shape=kanton), size=5.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2010,2))   + 
  scale_y_continuous(labels = percent, lim=c(0.07,0.15)) +
  scale_shape_manual(values=c(15,16,17,18,2),name = "") + # Change dot shapes 
  scale_color_manual(values=c("blue","grey54","red2","darkorchid","green4"),name = "") +
  scale_linetype_manual(values=c("dotdash","twodash","solid","dotted","longdash"),name = "") +
  theme(legend.direction = "vertical", legend.position = c(0.15,0.81), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=1))
ggsave(filename = "figure1-cantons.pdf", width = 18, height = 9.3)


p <- ggplot(data )
p +  geom_line(aes( y= P99d_ipol_missing, x=year,shape=kanton,linetype=kanton,color=kanton), size=3.5) + 
  geom_point(aes( y=P99d, x=year,shape=kanton), size=5.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2010,2))   + 
  scale_y_continuous(labels = percent, lim=c(0.07,0.15)) +
  scale_shape_manual(values=c(15,16,17,18,2),name = "") + # Change dot shapes 
  scale_linetype_manual(values=c("dotdash","twodash","solid","dotted","longdash"),name = "") +
  scale_color_manual(values=c("grey48","grey54","black","grey30","grey69"),name = "") +
  theme(legend.direction = "vertical", legend.position = c(0.15,0.81), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=1))
ggsave(filename = "figure1-cantons-bw.pdf", width = 18, height = 9.3)


# Time Series Plots Figure 2: Swiss Top Shares 1981-2010
# * Figure 2.a) Top 0.1%
data<-read.dta("fig2.dta")
head(data)

p <- ggplot(data )
p +   geom_line(aes( y= P999d_ipol, x=year, shape=factor(top01),linetype=factor(top01)), size=2.5) + 
  geom_point(aes( y=P999d, x=year,shape=factor(top01)), size=5.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  geom_vline(x=1995, size=1)+
  geom_vline(x=2002, size=1)+
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2010,2))   + 
  scale_y_continuous(labels = percent,lim=c(0.02,0.05)) +
  scale_linetype_manual(values=c("solid"),name = "") +
  scale_shape_manual(values=c(15),name = "") + # Change dot shapes
  theme(legend.direction = "vertical", legend.position = c(0.1,0.84), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure2a-top01.pdf", width = 18, height = 5.6)


# * Figure 2.b) Top 1%
data<-read.dta("fig2.dta")
head(data)

p <- ggplot(data )
p +   geom_line(aes( y= P99d_ipol, x=year, shape=factor(top1),linetype=factor(top1)), size=2.5) + 
  geom_point(aes( y=P99d, x=year,shape=factor(top1)), size=5.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  geom_vline(x=1995, size=1)+
  geom_vline(x=2002, size=1)+
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2010,2))   + 
  scale_y_continuous(labels = percent,lim=c(0.08,0.11)) +
  scale_linetype_manual(values=c("solid"),name = "") +
  scale_shape_manual(values=c(15),name = "") + # Change dot shapes
  theme(legend.direction = "vertical", legend.position = c(0.2,0.81), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure2b-top1.pdf", width = 18, height = 5.6)



# * Figure 2.c) Top 10-1%
data<-read.dta("fig2.dta")
head(data)
p <- ggplot(data )
p +   geom_line(aes( y= P10_1d_ipol, x=year, shape=factor(top10_1),linetype=factor(top10_1)), size=2.5) + 
  geom_point(aes( y=P10_1d, x=year,shape=factor(top10_1)), size=5.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  geom_vline(x=1995, size=1)+
  geom_vline(x=2002, size=1)+
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2010,2))   + 
  scale_y_continuous(labels = percent, lim=c(0.209,0.24)) +
  scale_linetype_manual(values=c("solid"),name = "") +
  scale_shape_manual(values=c(15),name = "") + # Change dot shapes
  theme(legend.direction = "vertical", legend.position = c(0.2,0.81), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure2c-top_10_1.pdf", width = 18, height = 5.6)




# * Figure 3: Top Shares in the long run
# * Figure 3a) Top 10% & Top 5%
mydata<-read.dta("fig3.dta")
head(mydata)

data <- subset(mydata, id >= 90 & id<=95)
head(data)
tail(data)

p <- ggplot(data )
p +   geom_line(aes( y= topshare_ipol, x=year, shape=factor(group),linetype=factor(group)), size=2.5) + 
  geom_point(aes( y=topshare, x=year,shape=factor(group)), size=5.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1930,2010,5))   + 
  scale_y_continuous(labels = percent,lim=c(0.175,0.35)) +
  scale_linetype_manual(values=c("solid","solid"),name = "") +
  scale_shape_manual(values=c(17,18),name = "") + # Change dot shapes
  theme(legend.direction = "horizontal", legend.position = c(0.15,0.95), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure3a-top_19332010.pdf", width = 18, height = 8.14)


# * Figure 3b) Top 10%-5%, Top 5-1%, Top 1%
mydata<-read.dta("fig3.dta")
head(mydata)

data <- subset(mydata, id == 99 | id==51 | id==105)
head(data)
tail(data)

p <- ggplot(data )
p +   geom_line(aes( y= topshare_ipol, x=year, shape=factor(group),linetype=factor(group)), size=2) + 
  geom_point(aes( y=topshare, x=year,shape=factor(group)), size=5.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1930,2010,5))   + 
  scale_y_continuous(labels = percent,lim=c(0.075,0.15)) +
  scale_linetype_manual(values=c("solid","dotted","solid"),name = "") +
  scale_shape_manual(values=c(17,18,4),name = "") + # Change dot shapes
  theme(legend.direction = "horizontal", legend.position = c(0.23,0.93), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure3b-top_19332010.pdf", width = 18, height = 7)


# * Figure 3c) Top 1-0.5%, Top 0.5-0.1%, Top 0.1%
mydata<-read.dta("fig3.dta")
head(mydata)

data <- subset(mydata, id == 999 | id==501 | id==2105)
head(data)
tail(data)

p <- ggplot(data )
p +   geom_line(aes( y= topshare_ipol, x=year, shape=factor(group),linetype=factor(group)), size=2) + 
  geom_point(aes( y=topshare, x=year,shape=factor(group)), size=5.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1930,2010,5))   + 
  scale_y_continuous(labels = percent,lim=c(0.02,0.05)) +
  scale_linetype_manual(values=c("solid","solid","dotted"),name = "") +
  scale_shape_manual(values=c(17,4,18),name = "") + # Change dot shapes
  theme(legend.direction = "horizontal", legend.position = c(0.3,0.93), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure3c-top_19332010.pdf", width = 15, height = 7)




# * Figure 4: Shares within shares
data<-read.dta("fig4.dta")
head(data)

p <- ggplot(data )
p + geom_line(aes( y=topshare_ipol, x=year, shape=factor(group),linetype=factor(group)), size=2) + 
  geom_point(aes( y=topshare, x=year, shape=factor(group)), size=5.5) +
  xlab("Year") + ylab("Share within Larger Top Group") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1930,2010,5))   + 
  scale_y_continuous(labels = percent,lim=c(0.25,0.4)) +
  scale_linetype_manual(values=c("solid","solid"),name = "") +
  scale_shape_manual(values=c(17,4),name = "") + # Change dot shapes
  theme(legend.direction = "vertical", legend.position = c(0.17,0.12), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure4-shares_within.pdf", width = 18, height = 7)



# Figure 5: Top shares international comparison
# Figure 5a): Top 1% shares international comparison
data<-read.dta("fig5.dta")
head(data)

p <- ggplot(data )
p + geom_line(aes( y=top1_ipol, x=year, shape=country,linetype=country,color=country), size=2.5) + 
  geom_point(aes( y=top1, x=year, shape=country), size=4.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1913,2013,10))   + 
  scale_y_continuous(labels = percent) +
  scale_linetype_manual(values=c("dotdash","twodash","twodash","solid","longdash"),name = "") +
  scale_shape_manual(values=c(18,1,16,17,5),name = "") + # Change dot shapes
  scale_color_manual(values=c("blue","grey40","grey70","red2","green4"),name = "") +
  theme(legend.direction = "vertical", legend.position = c(0.6,0.81), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure5a-internat_top1.pdf", width = 18, height = 9.3)


p <- ggplot(data )
p + geom_line(aes( y=top1_ipol, x=year, shape=country,linetype=country,color=country), size=2.5) + 
  geom_point(aes( y=top1, x=year, shape=country, color=country), size=4.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1913,2013,10))   + 
  scale_y_continuous(labels = percent) +
  scale_linetype_manual(values=c("dotdash","twodash","twodash","solid","longdash"),name = "") +
  scale_shape_manual(values=c(18,1,16,17,4),name = "") + # Change dot shapes
  scale_color_manual(values=c("grey45","grey80","grey70","black","grey25"),name = "") +
  theme(legend.direction = "vertical", legend.position = c(0.6,0.81), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure5a-internat_top1-bw.pdf", width = 18, height = 9.3)

# Figure 5b): Top 0.01% shares international comparison
p <- ggplot(data )
p + geom_line(aes( y=top001_ipol, x=year, shape=country,linetype=country,color=country), size=2.5) + 
  geom_point(aes( y=top001, x=year, shape=country), size=4.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1913,2013,10))   + 
  scale_y_continuous(labels = percent) +
  scale_linetype_manual(values=c("dotdash","twodash","twodash","solid","longdash"),name = "") +
  scale_shape_manual(values=c(18,1,16,17,5),name = "") + # Change dot shapes
  scale_color_manual(values=c("blue","grey40","grey70","red2","green4"),name = "") +
  theme(legend.direction = "vertical", legend.position = c(0.6,0.81), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +  
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure5b-internat_top001.pdf", width = 18, height = 9.3)

p <- ggplot(data )
p + geom_line(aes( y=top001_ipol, x=year, shape=country,linetype=country,color=country), size=2.5) + 
  geom_point(aes( y=top001, x=year, shape=country, color=country), size=4.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1913,2013,10))   + 
  scale_y_continuous(labels = percent) +
  scale_linetype_manual(values=c("dotdash","twodash","twodash","solid","longdash"),name = "") +
  scale_shape_manual(values=c(18,1,16,17,4),name = "") + # Change dot shapes
  scale_color_manual(values=c("grey45","grey80","grey70","black","grey25"),name = "") +
  theme(legend.direction = "vertical", legend.position = c(0.6,0.81), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +  
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure5b-internat_top001-bw.pdf", width = 18, height = 9.3)


# Figure 6: results of estimation strategies
# * Figure 6.a) Top 0.1%
mydata<-read.dta("fig6.dta")
data <- subset(mydata, year <= 2008) 
head(data)
tail(data)

p <- ggplot(data )
p + geom_line(aes( y= P999d_ipol, x=year, shape=factor(type),linetype=factor(type),color=factor(type)), size=2.5) + 
  geom_point(aes( y=P999d, x=year,shape=factor(type)), size=5.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  geom_vline(x=1995, size=1)+
  geom_vline(x=2002, size=1)+
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2008,2))   + 
  scale_y_continuous(labels = percent,lim=c(0.02,0.05)) +
  scale_shape_manual(values=c(15,16,17),name = "") + # Change linetypes +
  scale_linetype_manual(values=c("dotdash","dotted","solid"),name = "") +
  scale_color_manual(values=c("deeppink2","blue","springgreen4"),name = "") +
  theme(legend.direction = "vertical", legend.position = c(0.2,0.81), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure6a-estimations_top01.pdf", width = 18, height = 5.6)

p <- ggplot(data )
p + geom_line(aes( y= P999d_ipol, x=year, shape=factor(type),linetype=factor(type),color=factor(type)), size=2.5) + 
  geom_point(aes( y=P999d, x=year,shape=type, color=type), size=5.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  geom_vline(x=1995, size=1)+
  geom_vline(x=2002, size=1)+
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2008,2))   + 
  scale_y_continuous(labels = percent,lim=c(0.02,0.05)) +
  scale_shape_manual(values=c(15,16,17),name = "") + # Change linetypes +
  scale_linetype_manual(values=c("dotdash","dotted","solid"),name = "") +
  scale_color_manual(values=c("grey30","grey55","black"),name = "") +
  theme(legend.direction = "vertical", legend.position = c(0.2,0.81), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure6a-estimations_top01-bw.pdf", width = 18, height = 5.6)


# * Figure 6.b) Top 1%
p <- ggplot(data )
p + geom_line(aes( y= P99d_ipol, x=year, shape=factor(type),linetype=factor(type),color=factor(type)), size=2.5) + 
  geom_point(aes( y=P99d, x=year,shape=factor(type)), size=5.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  geom_vline(x=1995, size=1)+
  geom_vline(x=2002, size=1)+
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2008,2))   + 
  scale_y_continuous(labels = percent,lim=c(0.08,0.11)) +
  scale_shape_manual(values=c(15,16,17),name = "") + # Change linetypes +
  scale_linetype_manual(values=c("dotdash","dotted","solid"),name = "") +
  scale_color_manual(values=c("deeppink2","blue","springgreen4"),name = "") +
  theme(legend.direction = "vertical", legend.position = c(0.2,0.81), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure6b-estimations_top1.pdf", width = 18, height = 5.6)


p <- ggplot(data )
p + geom_line(aes( y= P99d_ipol, x=year, shape=factor(type),linetype=factor(type),color=factor(type)), size=2.5) + 
  geom_point(aes( y=P99d, x=year,shape=type, color=type), size=5.5) +
  xlab("Year") + ylab("Share of Total Income") + 
  geom_vline(x=1995, size=1)+
  geom_vline(x=2002, size=1)+
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2008,2))   + 
  scale_y_continuous(labels = percent,lim=c(0.08,0.11)) +
  scale_shape_manual(values=c(15,16,17),name = "") + # Change linetypes +
  scale_linetype_manual(values=c("dotdash","dotted","solid"),name = "") +
  scale_color_manual(values=c("grey30","grey55","black"),name = "") +
  theme(legend.direction = "vertical", legend.position = c(0.2,0.81), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure6b-estimations_top1-bw.pdf", width = 18, height = 5.6)




# * Figure 7: Expenditure-based tax units and special cases among the top 0.1%
data<-read.dta("fig7.dta")
p <- ggplot(data )
p +   geom_line(aes( y= P999_ipol, x=year, shape=factor(group),linetype=factor(group)), size=2.5) + 
  geom_point(aes( y=P999_, x=year,shape=factor(group)), size=5.5) +
  xlab("Year") + ylab("Special Cases among the Top 0.1%") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1970,2010,5))   + 
  scale_y_continuous(labels = percent, lim=c(0,0.35)) +
  scale_linetype_manual(values=c("solid","dotted",   "solid","dashed"),name = "") +
  scale_shape_manual(values=c(17,17, 16,16),name = "") + # Change dot shapes
  theme(legend.direction = "vertical", legend.position = c(0.3,0.88), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +  
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=2))+
  theme(plot.background=element_rect(fill="white"), # together with the next line, this allows to readjust the plot region
        plot.margin = unit(c(0.5, 0.5, 0.5, 0.6), "cm")) #top, right, bottom, left
ggsave(filename = "figure7-special_cases.pdf", width = 18, height = 8.14)


# * Figure 8: Top 1% income shares of total income and labor income
mydata <- read.dta("fig8_fig9_fig10.dta")
data <- subset(mydata, cat==0 | cat==3) 
head(data)
tail(data)

p <- ggplot(data )
p +   geom_line(aes( y= P99_ipol, x=year, shape=factor(category), linetype=factor(category), color=factor(category)), size=2.5) + 
  geom_point(aes( y=P99, x=year,shape=factor(category), color=category), size=4.5) +
  xlab("Year") + ylab("Income Share in Percent") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2010,2))   + 
  scale_y_continuous(labels = percent,lim=c(0.05,0.12)) +
  scale_linetype_manual(values=c("solid","dashed"),name = "", breaks=c("Total income (tax units)","Labor income (employees and self-employed)")) + # Change linetypes and order of legend
  scale_shape_manual(values=c(15,16),name = "", breaks=c("Total income (tax units)","Labor income (employees and self-employed)")) + # Change dottypes and order of legend
  scale_color_manual(values=c("black","grey55"),name = "", breaks=c("Total income (tax units)","Labor income (employees and self-employed)")) +
  theme(legend.direction = "vertical", legend.position = c(0.25,0.89), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +  
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure8-laborshares.pdf", width = 18, height = 7)



# Figure 9: Top income shares of employees and self-employed, 1981--2010
mydata <- read.dta("fig8_fig9_fig10.dta")
data <- subset(mydata, cat>0) 
head(data)
tail(data)

# Figure 9a) Top 1% shares employees and self-employed
p <- ggplot(data )
p +    geom_line(aes( y= P99, x=year, shape=factor(category), linetype=factor(category)), size=2) + 
  geom_point(aes( y=P99, x=year,shape=factor(category)), size=4.5) +
  xlab("Year") + ylab("Income Share in Percent") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2010,2))   + 
  scale_y_continuous(labels = percent,lim=c(0.025,0.15)) +
  scale_linetype_manual(values=c("dashed","solid","dotted"),name = "") +
  scale_shape_manual(values=c(0,15,16),name = "") + # Change dottypes
  theme(legend.direction = "vertical", legend.position = c(0.5,0.1), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +  
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure9a-laborshares_p99.pdf", width = 18, height = 9.3)


# Figure 9b) Top 0.1% shares employees and self-employed
p <- ggplot(data )
p +    geom_line(aes( y= P999, x=year, shape=factor(category), linetype=factor(category)), size=2) + 
  geom_point(aes( y=P999, x=year,shape=factor(category)), size=4.5) +
  xlab("Year") + ylab("Income Share in Percent") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2010,2))   + 
  scale_y_continuous(labels = percent,lim=c(0,0.06)) +
  scale_linetype_manual(values=c("dashed","solid","dotted"),name = "") +
  scale_shape_manual(values=c(0,15,16),name = "") + # Change dottypes
  theme(legend.direction = "vertical", legend.position = c(0.5,0.1), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +  
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure9b-laborshares_p999.pdf", width = 18, height = 9.3)



# Figure 10: Change in top 1% income shares of labor income of employees and self- employed, and total income for all taxpayers, 1981???2010
mydata <- read.dta("fig8_fig9_fig10.dta")
data <- subset(mydata, cat<3) 
head(data)
tail(data)

p <- ggplot(data )
p +    geom_line(aes( y= change_P99_ipol, x=year, shape=factor(category), linetype=factor(category), color=category), size=2) + 
  geom_point(aes( y=change_P99, x=year,shape=factor(category), color=category), size=5.5) +
  xlab("Year") + ylab("Change in Top 1% Income Share since 1981") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1980,2010,2))   + 
  scale_y_continuous(labels = percent) +
  scale_linetype_manual(values=c("solid","dotted","dashed"),name = "") +
  scale_shape_manual(values=c(0,16,16),name = "") + # Change dottypes
  scale_color_manual(values=c("black","black","grey55"),name = "") +
  theme(legend.direction = "vertical", legend.position = c(0.2,0.9), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank())  +  
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure10-change_p99.pdf", width = 18, height = 9.3)





# * Figure 12 Top Wealth shares
  # 12a) Top 10%-5%, Top 5-1%, Top 1% Wealth shares
  mydata<-read.dta("fig12.dta")
  tail(mydata)
  
  data <- subset(mydata, gr<4)
  head(data)
  tail(data)
  p <- ggplot(data )
  p +   geom_line(aes( y= wealthsh_ipol, x=year, shape=factor(group),linetype=factor(group)), size=2) + 
    geom_point(aes( y=wealthsh, x=year,shape=factor(group)), size=5.5) +
    xlab("Year") + ylab("Share of Total Taxable Wealth") + 
    theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
    scale_x_continuous(breaks=seq(1913,2013,8))   + 
    scale_y_continuous(labels = percent, lim=c(0,0.5)) +
    scale_linetype_manual(values=c("solid","dotted","solid"),name = "") +
    scale_shape_manual(values=c(17,18,4),name = "") + # Change dot shapes
    theme(legend.direction = "vertical", legend.position = c(0.8,0.13), legend.box="horizontal")  +
    theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
    theme(legend.title=element_blank()) +  
    theme(legend.key.height=unit(2,"line")) + # increase space in legend
    theme(legend.key.width=unit(4,"line")) +
    theme(axis.title.y = element_text(vjust=0.5))
  ggsave(filename = "figure12a-topwealth.pdf", width = 18, height = 9.3)

data <- subset(mydata, gr>3)
head(data)
tail(data)
p <- ggplot(data )
p +   geom_line(aes( y= wealthsh_ipol, x=year, shape=factor(group),linetype=factor(group)), size=2) + 
  geom_point(aes( y=wealthsh, x=year,shape=factor(group)), size=5.5) +
  xlab("Year") + ylab("Share of Total Taxable Wealth") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1913,2013,8))   + 
  scale_y_continuous(labels = percent, lim=c(0,0.25)) +
  scale_linetype_manual(values=c("solid","dotted","solid"),name = "") +
  scale_shape_manual(values=c(17,18,4),name = "") + # Change dot shapes
  theme(legend.direction = "vertical", legend.position = c(0.8,0.13), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +  
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(4,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure12b-topwealth.pdf", width = 18, height = 9.3)




# * Figure 13: Top Wealth shares corrected for pension wealth
  #  Figure 13a) Top 10% (color)
mydata<-read.dta("fig13.dta")
data <- subset(mydata, gr<4)
head(data)
tail(data)

  
  p <- ggplot(data )
  p +   geom_line(aes( y= wealthsh_ipol, x=year, shape=factor(group),linetype=factor(group), color=group), size=2.5) + 
    geom_point(aes( y=wealthsh, x=year,shape=factor(group)), size=5.5) +
    xlab("Year") + ylab("Share of Total Wealth") + 
    theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
    scale_x_continuous(breaks=seq(1910,2010,10))   + 
    scale_y_continuous(labels = percent, lim=c(0.3,0.95)) +
    scale_linetype_manual(values=c("solid","dotted","dashed"),name = "") +
    scale_color_manual(values=c("lightblue","blue", "blue3"),name = "") +
    scale_shape_manual(values=c(17,17,17),name = "") + # Change dot shapes
    theme(legend.direction = "vertical", legend.position = c(0.25,0.17), legend.box="horizontal")  +
    theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
    theme(legend.title=element_blank()) +  
    theme(legend.key.height=unit(2,"line")) + # increase space in legend
    theme(legend.key.width=unit(5,"line")) +
    theme(axis.title.y = element_text(vjust=0.5))
  ggsave(filename = "figure13a-top10-color.pdf", width = 18, height = 9.3)

#  Figure 13a) Top 10% (black and white)
p <- ggplot(data )
p +   geom_line(aes( y= wealthsh_ipol, x=year, shape=factor(group),linetype=factor(group), color=group), size=2.5) + 
  geom_point(aes( y=wealthsh, x=year,shape=group, color=group), size=5.5) +
  xlab("Year") + ylab("Share of Total Wealth") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1910,2010,10))   + 
  scale_y_continuous(labels = percent, lim=c(0.3,0.95)) +
  scale_linetype_manual(values=c("solid","dotted","dashed"),name = "") +
  scale_color_manual(values=c("black","gray60", "gray30"),name = "") +
  scale_shape_manual(values=c(17,17,17),name = "") + # Change dot shapes
  theme(legend.direction = "vertical", legend.position = c(0.25,0.17), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +  
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(5,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))
ggsave(filename = "figure13a-top10-bw.pdf", width = 18, height = 9.3)


#  Figure 13b) Top 1% Top 0.1%(color)
data <- subset(mydata, gr>3)
head(data)
tail(data)
p <- ggplot(data )
p +   geom_line(aes( y= wealthsh_ipol, x=year, shape=factor(group),linetype=factor(group), color=group), size=2.5) + 
  geom_point(aes( y=wealthsh, x=year,shape=group), size=5.5) +
  xlab("Year") + ylab("Share of Total Wealth") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1910,2010,10))   + 
  scale_y_continuous(labels = percent, lim=c(0,0.5)) +
  scale_linetype_manual(values=c("solid","dotted","dashed",  "solid","dotted","dashed"),name = "") +
  scale_color_manual(values=c("lightblue","blue", "blue3", "lightgreen","springgreen4", "springgreen4"),name = "") +
  scale_shape_manual(values=c(17,17,17, 16,16,16),name = "") + # Change dot shapes
  theme(legend.direction = "vertical", legend.position = c(0.49,0.11), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +  
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(5,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))+
  guides(linetype=guide_legend(ncol=2))
ggsave(filename = "figure13b-top1-color.pdf", width = 18, height = 9.3)


data <- subset(mydata, gr>3)
head(data)
tail(data)
p <- ggplot(data )
p +   geom_line(aes( y= wealthsh_ipol, x=year, shape=factor(group),linetype=factor(group), color=group), size=2.5) + 
  geom_point(aes( y=wealthsh, x=year,shape=group, color=group), size=5.5) +
  xlab("Year") + ylab("Share of Total Wealth") + 
  theme_bw_finegrid(base_size = 30)  +  # Size of y- and x-axis legends
  scale_x_continuous(breaks=seq(1910,2010,10))   + 
  scale_y_continuous(labels = percent, lim=c(0,0.5)) +
  scale_linetype_manual(values=c("solid","dotted","dashed",  "solid","dotted","dashed"),name = "") +
  scale_color_manual(values=c("black","gray60", "gray30",  "black","gray60", "gray30"),name = "") +
  scale_shape_manual(values=c(17,17,17, 16,16,16),name = "") + # Change dot shapes
  theme(legend.direction = "vertical", legend.position = c(0.49,0.11), legend.box="horizontal")  +
  theme(legend.background = element_rect(colour = 'black', fill = 'white', size = 0.5)) +
  theme(legend.title=element_blank()) +  
  theme(legend.key.height=unit(2,"line")) + # increase space in legend
  theme(legend.key.width=unit(5,"line")) +
  theme(axis.title.y = element_text(vjust=0.5))+
  guides(linetype=guide_legend(ncol=2))
ggsave(filename = "figure13b-top1-bw.pdf", width = 18, height = 9.3)

